﻿using System;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Text;
using SubSonic.Repository;
using xtra.domain.Subsonic3;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;

namespace sb.web {
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class CustomISService{
        IRepository repo = new SimpleRepository(SimpleRepositoryOptions.None);

        #region Core
        [OperationContract]
        public List<CoreEntity> GetCoreModules() {
            return (from a in repo.All<CoreEntity>()
                        select a).ToList();
        }

        [OperationContract]
        public List<BaseEntity> GetCustomItemSource(string t){
            List<BaseEntity> l = new List<BaseEntity>();

            var test = (from a in repo.All<CoreEntity>()
                        where a.Type == t
                        select a).ToList();


            foreach (var item in test) {
                var o = item.GetType().GetProperty(t).GetValue(item, null) as IQueryable;
                
                foreach (BaseEntity b in o) {
                    l.Add(b);
                }
            }

            return l;
        }
        #endregion
    }
}
